﻿Imports System.Globalization

Module Variables
    Public BYR_USD_CONV As Integer
    Public NDS_COEFF As Double
    Public Const EXPORT_EXCEL_DEFAULT_FILENAME As String = "prais_shini-data"
    Public Const RESULT_SHEET_NAME_TIRES As String = "Шины"
    Public Const RESULT_SHEET_NAME_DISCS As String = "Диски"
    Public Const SUCCOBJECT_FROMCODES As String = "SUCCOBJECT_FROMCODES"
    'Public Const RESULT_SITECODE_COLUMN As Integer = 17
    Public Const POST_SITE_URL As String = "http://minskshina.by/update_products.php"
    Public Const RESULT_SITECODE_COLUMN As Integer = 1
    Public Const RESULT_AVAIL_COLUMN As Integer = 18
    Public Const QUANTITY_THRESHOLD As Integer = 5
    Public Const err_csv_delim As String = ";"
    Public Const sitecode_null As String = "---"
    Public Const errorlogfile As String = "error.log"
    Public Function Encoding1251() As System.Text.Encoding
        Encoding1251 = System.Text.Encoding.GetEncoding(1251)
    End Function
    Public Function HardConvertToDouble(s As String) As Double
        Dim d As Double
        Dim dset As Boolean = False
        Dim ci As New List(Of CultureInfo)
        For Each t As String In {"ru-RU", "en-US"}
            ci.Add(CultureInfo.CreateSpecificCulture(t))
        Next
        ci.Add(CultureInfo.CurrentCulture)
        For Each t As CultureInfo In ci
            If Double.TryParse(s, NumberStyles.Float, t, d) Then
                dset = True
                Exit For
            End If
        Next
        If dset = False Then
            Throw New ArgumentException
        End If
        HardConvertToDouble = d
    End Function
    Function DoubleToExcelString(d As Double) As String
        DoubleToExcelString = d.ToString(CultureInfo.CreateSpecificCulture("en-US"))
    End Function

    Function succOut(succs_global As List(Of SuccObject)) As List(Of String)
        'Dim ans As New SortedDictionary(Of String, SuccObject)
        'For Each t As SuccObject In succs_global
        '    If ans.ContainsKey(t.code) Then
        '        If t.compareTo(ans(t.code)) > 0 Then ' if current has more priority
        '            ans(t.code) = t
        '        End If
        '    Else
        '        ans.Add(t.code, t)
        '    End If

        'Next
        Dim l As New List(Of String)
        'For Each t As SuccObject In ans.Values
        For Each t As SuccObject In succs_global
            l.Add(t.toString)
        Next
        succOut = l
    End Function
End Module
